<%@page import="com.dfhc.util.StringHelper"%>
<%@ page import="org.quickbundle.orgauth.rmpartytype.util.IRmPartyTypeConstants" %>
<%@ page import="org.quickbundle.orgauth.rmparty.util.IRmPartyConstants" %>
<%@ page import="org.quickbundle.orgauth.rmauthorize.util.IRmAuthorizeConstants" %>
<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!--_meta 作为公共模版分离出去-->
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />

<!-- 全局js 和css包 -->
<%@ include file="/jsp/include/web/new/global.jsp" %>
<title> </title>

<%@ taglib uri="/dfhc" prefix="dfhc" %>
</head>
<body>

<article class="page-container">
	<form action="" method="post" class="form form-horizontal" id="form-add">
	   <input type="hidden" id="id" name="id" value="${bean.id}">
							
		<dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmAuthorizeConstants.TABLE_COLUMN_CHINESE.get("name")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input templateId="h_ui_input" class="input-text"  value="${bean.name}"  id="name"  placeholder=""  name="name" />	
	    </dfhc:div>
	    <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmAuthorizeConstants.TABLE_COLUMN_CHINESE.get("bs_keyword")%>：</dfhc:label>	    
	    <dfhc:div templateId="h_ui_div_label_div" >	         
			<dfhc:input templateId="h_ui_input" class="input-text"  value="${bean.bs_keyword}"  id="bs_keyword"  placeholder=""  name="bs_keyword" />			
	 	</dfhc:div>
	  </dfhc:div>
	  
	  <dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmAuthorizeConstants.TABLE_COLUMN_CHINESE.get("is_alone_table")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	 
			<dfhc:select templateId="h_ui_select" size="1" name="is_alone_table" id="is_alone_table" pleaseSelect="1" defaultValue="${bean.is_alone_table}" sqlOption="code" code="<%=IRmAuthorizeConstants.DICTIONARY_RM_YES_NOT%>" />					
	    </dfhc:div>
	    <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmAuthorizeConstants.TABLE_COLUMN_CHINESE.get("authorize_resource_table_name")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input templateId="h_ui_input" class="input-text"  value="${bean.authorize_resource_table_name}"  id="authorize_resource_table_name"  placeholder=""  name="authorize_resource_table_name" />
	    </dfhc:div>
	  </dfhc:div>
	  
	  <dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmAuthorizeConstants.TABLE_COLUMN_CHINESE.get("authorize_resrec_table_name")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input  templateId="h_ui_input" type="text"   name="authorize_resrec_table_name" id="authorize_resrec_table_name" value="${bean.authorize_resrec_table_name}" />	
	    </dfhc:div>
	    <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmAuthorizeConstants.TABLE_COLUMN_CHINESE.get("authorize_affix_table_name")%>：</dfhc:label>	    
	    <dfhc:div templateId="h_ui_div_label_div" >	         
			<dfhc:input  templateId="h_ui_input" value="${bean.authorize_affix_table_name}" id="authorize_affix_table_name"  name="authorize_affix_table_name"   />
	 	</dfhc:div>
	  </dfhc:div>
	  
	  <dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmAuthorizeConstants.TABLE_COLUMN_CHINESE.get("settiing_option")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:select templateId="h_ui_select" size="1" name="settiing_option" id="settiing_option" pleaseSelect="1" defaultValue="${bean.settiing_option}" sqlOption="code" code="<%=IRmAuthorizeConstants.DICTIONARY_RM_OPTION_TYPE%>" />		
	    </dfhc:div>
	    <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmAuthorizeConstants.TABLE_COLUMN_CHINESE.get("custom_code")%>：</dfhc:label>	    
	    <dfhc:div templateId="h_ui_div_label_div" >	         
			<dfhc:input  templateId="h_ui_input" value="${bean.description}" id="custom_code"  name="custom_code"   />
	 	</dfhc:div>
	  </dfhc:div>
	  
	  <dfhc:div templateId="h_ui_div_row_cl">
	   <dfhc:label	 templateId="h_ui_div_label_row_cl"><%=IRmAuthorizeConstants.TABLE_COLUMN_CHINESE.get("description")%>：</dfhc:label> 	    
	    <dfhc:div templateId="h_ui_div_label_div" >	        
			<dfhc:input  templateId="h_ui_input" type="text"   name="description" id="description" value="${bean.description}" />	
	    </dfhc:div>
	  </dfhc:div>
	  
	  
		<dfhc:div templateId="h_ui_div_row_cl">
			<dfhc:div templateId="h_ui_div_pop_up_button">
				<dfhc:button templateId="h_ui_submit_button" />
				<dfhc:button templateId="h_ui_cancel_button" onclick="cancel();" />
				<dfhc:button templateId="h_ui_reset_button" onclick="reset();" />
			</dfhc:div>
		</dfhc:div>
	</form>
</article>

<dfhc:pageSign templateId = "h_ui_pagesign_div"  is_set_parameter="子表RmParty:a">
 <dfhc:template templateUrl="/pubController/getLayoutTemp/?jspUrl=/temp/hui-hx-BodyTemp" >	 
 	<dfhc:region name="searchRegion"> 
	<form name="searchForm" id="searchForm" action="" method="post">
 	<dfhc:div templateId="h_ui_div_search">
	</dfhc:div> 
	</form>
     </dfhc:region> 
     <dfhc:region name="buttonRegion">
        <dfhc:div templateId="h_ui_div_table_button">
        <dfhc:span templateId="h_ui_button_span">
         <dfhc:button templateId="h_ui_add_button" onclick="_showPage('添加模块','${pageContext.request.contextPath }/RmPartyByHUI/addPage','100%','100%')" />
         <dfhc:button templateId="h_ui_update_button" onclick="singleEdit('修改模块','${pageContext.request.contextPath }/RmPartyByHUI/showPage','100%','100%')" />
		 <dfhc:button templateId="h_ui_delete_button" onclick="singleDelete('${pageContext.request.contextPath }/RmPartyByHUI/delete')" />
		<dfhc:button templateId="h_ui_detail_button" onclick="detailByHX('详情','${pageContext.request.contextPath }/RmPartyByHUI/detail','${bean.id}')" />
		</dfhc:span>
		<dfhc:span templateId="h_ui_total_record_num_span">${RM_PAGE_VO.recordCount}</dfhc:span>		
	    </dfhc:div>		       
     </dfhc:region> 
    <dfhc:region name="tableRegion">
    	<dfhc:table templateId="table_h_ui" id="tableon" >    	
		<dfhc:thead>
			<dfhc:tr> 
				<dfhc:th width="25">
				   <dfhc:checkbox name="allId" />
				</dfhc:th>	
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("party_type_id")%></dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("old_party_id")%></dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("name")%></dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("is_inherit")%></dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("email")%></dfhc:title>
				</dfhc:th>
				
				<dfhc:th width="100">
				   <dfhc:title templateId="title_h_ui" ><%=IRmPartyConstants.TABLE_COLUMN_CHINESE.get("description")%></dfhc:title>
				</dfhc:th>
				
			</dfhc:tr>
    	   </dfhc:thead>			
		</dfhc:table>           
     </dfhc:region>        
</dfhc:template> 

</dfhc:pageSign>

<script type="text/javascript">
var table1;
var newusrl=getRootPath()+"/RmPartyTypeByHUI";
$(function(){
	var party_type_id = "${bean.id}";
	_table = $('.table-sort').DataTable({	
	     dom: 'Zlfrtip',	   		
		 ajax : function(data, callback, settings) {
		       var param =  splitParameter(data); 
               $.ajax({  
                       type: "GET",  
                       url: getRootPath()+"/RmPartyByHUI/ajaxList?party_type_id="+party_type_id,  
                       cache : false,  //禁用缓存  
                       data:param,   
                       dataType: "json",  
                       success: function(result) {  
                               //异常判断与处理  
                               if (result.status=='0') {  
                                   alert(result.message);  
                                   return;  
                               }  
                               //封装返回数据  
                               var returnData = {};  
                               returnData.draw = data.draw;//这里直接自行返回了draw计数器,应该由后台返回  
                               returnData.recordsTotal = result.recordsTotal;//总记录数  
                               returnData.recordsFiltered = result.recordsTotal;//后台不实现过滤功能，每次查询均视作全部结果  
                               returnData.data = result.data;  
                               //调用DataTables提供的callback方法，代表数据已封装完成并传回DataTables进行渲染  
                               //此时的数据需确保正确无误，异常判断应在执行此回调前自行处理完毕  
                               callback(returnData);  
                               //更新总记录数
                               $("#totalRecodSpan").html('共有数据：<strong>'+result.recordsTotal+'</strong> 条</span>');
                       },  
                       error: function(XMLHttpRequest, textStatus, errorThrown) {  
                           alert("查询失败");  
                       }  
                   });  
           },  
		"columns": [
		  {
		    "data":"id",
		    "width":"50px",
			"render":function(data,type,row,meta){
			   var content='<input type="checkbox" name="allId" value="'+row.id+'"/>';
			   return content; 
			}
		  },
		  {"data":"party_type_id"},
		  {"data":"old_party_id"},
		  {"data":"name"},
		  {"data":"is_inherit",
			  "defaultContent":"",
			    render:function(data,type,row,meta){
			    	var content;
				   	if(row.is_inherit!=null && row.is_inherit!= ""){
					    if(row.is_inherit=='1'){
					    	content = '是';
					    }else{
					    	content = '否';
					    }			 
				  }
			    return content; 
			  }  
		  },
		  {"data":"email"},
		  {"data":"description"}
		],
		"columnDefs": [ {"searchable": false,
           "orderable": false,
           "targets": 0 }]  				
	});
	_table.on( 'draw.dt', function () {
	    var PageInfo = $('.table-sort').DataTable().page.info();
	         _table.column(0, { page: 'current' }).nodes().each( function (cell, i) {
	            cell.innerHTML = cell.innerHTML+"&nbsp;&nbsp;&nbsp;"+(i + 1);
	        } );
	    } );
	
	$("#form-add").validate({
		rules:{
			bs_keyword:{			
			},
			name:{			
			},
			icon:{			
			},
			description:{			
			},
			is_custom_attribute:{			
			},
			is_allow_hanging_user:{			
			},
			is_allow_hanging_role:{			
			}
		},
 		messages: {
 			bs_keyword:{
	           },
	           name:{
	           },
	           icon:{
	           },
	           description:{
	           },
	           is_custom_attribute:{
	           },
	           is_allow_hanging_user:{
	           },
	           is_allow_hanging_role:{
	           }
	    },		
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$("input[type='checkbox']").each(function(){
				if($("input[type='checkbox']").is(':checked')){
					$('#checkboxName').val('1');
				}
			}); 
			<c:if test="${empty bean}"> 
			var url = getRootPath()+"/RmPartyTypeByHUI/insert?jsguid="+$('#id').val();
			</c:if>
			<c:if test="${not empty bean}"> 
			var url = getRootPath()+"/RmPartyTypeByHUI/update?jsguid="+$('#id').val();
			</c:if>
			//提交成功关闭
			submitAjax(url,$("#form-add").serialize(),newusrl); 
			window.location.href=newusrl;
			/* window.location.reload(); */
		}
	});
});
/*拼接参数*/
function splitParameter(data){
	 var paramJsonStr = $(searchForm).serializeObject();
	 //组装 排序参数
	 if(data.order && data.order.length && data.order[0]){
	  data.sort = data.columns[data.order[0].column].data;
     if(data.sort!='0'){
     	data.dir = data.order[0].dir;
     }else{
       data.sort ='';
       data.dir='';
     }
	}  
	var retVal;
	retVal = $.extend( {}, data,paramJsonStr); 
	return retVal;
}


$.fn.serializeObject=function(){
   var o = {};
   var a = this.serializeArray();
   $.each(a, function() {
       if (o[this.name] !== undefined) {
           if (!o[this.name].push) {
               o[this.name] = [o[this.name]];
           }
           o[this.name].push(this.value || '');
       } else {
           o[this.name] = this.value || '';
       }
   });
   return o;
};
/**
* 查询定制项目模块
*/
function _searchData(){	
	$('.table-sort').DataTable().ajax.reload();
} 	
function submitAjax(url,param,successUrl){
 	//url后面自动带jsguid
	if(url.indexOf("jsguid")==-1){
		 if(url.indexOf("?")==-1){
			   url = url+"?jsguid="+__global_guid;
		 }else{
			   url = url+"&jsguid="+__global_guid;
		 }
	}
	//url 后面自动带csrf 编码
	if(!isStrEmpty($('#_csrfcode_').val())){
		if (url.indexOf("?") == -1) {
			url = url + "?_csrfcode_=" + $('#_csrfcode_').val();
		} else {
			url = url + "&_csrfcode_=" + $('#_csrfcode_').val();
		}
	}
 
	 $.ajax({
	    type:'post',//可选get
	    url:url,
	    data:param,//送评表的表格id属性值
	    dataType:'json',
	    async:false , //false为同步
	    success:function(data,status){
	      //更新csrf随机码
	      $("#_csrfcode_").val(data._csrfcode_);
		  if(data.status=="0"){
		  	  layer.msg(data.message,{icon:1,time:1000});
			  //alert(data.message);
			  return false;
	   	   }else{	   	      
	   		  alert(data.message);
	   		  layer.msg(data.message,{icon:1,time:1000});
	   		  if(!isStrEmpty(successUrl)){
	   		    window.location.href=successUrl;
	   		  }	   		  
	   		  return true;   		
	   	   }
		   	
	   },
	   error:function(xhr,s1,s2){
			var  message= xhr.responseText;
	    	var  json = jQuery.parseJSON(message);
	
			if($.trim(json.exception).length==0){
				alert('数据异常,请刷新页面重试');
			}else{
				alert(json.exception);
			}
			return false;			
	   }
	   });
}
function singleDelete(url){
	//判断是否选择
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择删除的记录!");
       return;
    }  
    
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids+'&jsguid='+ids;
    }else{
    	newUrl = url+'?id='+ids+'&jsguid='+ids;
    }
    //url 后面自动带csrf 编码
	if(!isStrEmpty($('#_csrfcode_').val())){
		if (newUrl.indexOf("?") == -1) {
			newUrl = newUrl + "?_csrfcode_=" + $('#_csrfcode_').val();
		} else {
			newUrl = newUrl + "&_csrfcode_=" + $('#_csrfcode_').val();
		}
	}
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: newUrl,
			dataType: 'json',
			success: function(data){
				//$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
				$('.table-sort').DataTable().ajax.reload();
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
	$('.table-sort').DataTable().ajax.reload();
}
//详情
function detail(title,url,w,h){
	//判断用户是否选择
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){
     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择记录!");
       return;
    }  
    
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids+'&jsguid='+ids;
    }else{
    	newUrl = url+'?id='+ids+'&jsguid='+ids;
    }
	var neww;
    var newh;
    
    if(w.indexOf("%")!=-1){
      neww = w; 
    }else{
      neww = w+'px';
    }
    if(h.indexOf("%")!=-1){
      newh = h; 
    }else{
      newh = h+'px';
    }
	layer.open({
			type: 2,
			area: [neww, newh],
			fix: true,
			shade:0.4,
			title: title,
			content: newUrl,
            maxmin:true,
			cancel:function(){
				window.location.reload();
			}
	});
}
function back(){
	window.location.href=getRootPath()+"/RmPartyTypeByHUI";
}
function deleteByHX(url,ids){
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids+'&jsguid='+ids;
    }else{
    	newUrl = url+'?id='+ids+'&jsguid='+ids;
    }
    //url 后面自动带csrf 编码
	if(!isStrEmpty($('#_csrfcode_').val())){
		if (newUrl.indexOf("?") == -1) {
			newUrl = newUrl + "?_csrfcode_=" + $('#_csrfcode_').val();
		} else {
			newUrl = newUrl + "&_csrfcode_=" + $('#_csrfcode_').val();
		}
	}
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: newUrl,
			dataType: 'json',
			success: function(data){
				//$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
				$('.table-sort').DataTable().ajax.reload();
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
	$('.table-sort').DataTable().ajax.reload();
}
//修改
function Edit(title,url,w,h,ids){
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids+'&jsguid='+ids;
    }else{
    	newUrl = url+'?id='+ids+'&jsguid='+ids;
    }
	var neww;
    var newh;
    
    if(w.indexOf("%")!=-1){
      neww = w; 
    }else{
      neww = w+'px';
    }
    if(h.indexOf("%")!=-1){
      newh = h; 
    }else{
      newh = h+'px';
    }
	layer.open({
			type: 2,
			area: [neww, newh],
			fix: true,
			shade:0.4,
			title: title,
			content: newUrl,
            maxmin:true,
			cancel:function(){
				window.location.reload();
			}
	});
}
function detailByHX(title,url,rmPartyTypeId){
	var len = $('input[name="allId"]:checked').length;
    var count=0;
    var ids='';
     $('input[name="allId"]:checked').each(function(){
     	
     	var dataId =$(this).val();
     	if(dataId !== undefined && dataId!='on'){
     		ids+=dataId
         	if(len!=1){
         		ids+=","
         	}
         	count++;
     	}
     });  
    if(count==0){
       alert("请选择记录!");
       return;
    }  
    
    if(count>1){
       alert("只能选择一条记录!");
       return;	
    }
    var newUrl ;
    if(url.indexOf("?")>=0){
    	newUrl = url+'&id='+ids+'&jsguid='+ids;
    }else{
    	newUrl = url+'?id='+ids+'&jsguid='+ids;
    }
    newUrl= newUrl+'&rmPartyTypeId='+rmPartyTypeId;
	window.location.href=newUrl;
}
function refresh(){
	$('.table-sort').DataTable().ajax.reload();
}
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>
